﻿using RockBus.Monitoring.DataContracts.Configuration;
using System.Diagnostics;

namespace RockBus.Monitoring
{
    public static class PerformanceCounterConfigurationBaseExtensions
    {
        public static bool CounterExists(this PerformanceCounterConfigurationBase pccb)
        {
            return System.Diagnostics.PerformanceCounterCategory.CounterExists(pccb.CounterName, pccb.CategoryName);
        }

        public static bool Exists(this PerformanceCounterInstanceConfiguration pcic, PerformanceCounterCategoryType categoryType)
        {
            switch (categoryType)
            {
                case PerformanceCounterCategoryType.SingleInstance:
                    return System.Diagnostics.PerformanceCounterCategory.CounterExists(pcic.CounterName, pcic.CategoryName);

                case PerformanceCounterCategoryType.MultiInstance:
                    return System.Diagnostics.PerformanceCounterCategory.InstanceExists(pcic.InstanceName, pcic.CategoryName);

                default:
                case PerformanceCounterCategoryType.Unknown:
                    return false;
            }
        }
    }
}